
const service = axios.create({
    // api的base_url
    baseURL: HTTP_ROOT_PATH,
    timeout: 5000 // 请求超时时间
});
service.interceptors.request.use(
    config => {
        config.headers["Authorization"] = window.localStorage.getItem("token");
        return config;
    },
    error => {
        console.log("axios request请求异常====>", error);
        Promise.reject(error);
    }
);
service.interceptors.response.use(
    response => {
        // 对响应数据做处理，例如只返回data部分
        const res = response.data;
        return res;
    },
    error => {
        let errorMessage = "请求异常";
        if (error.response && error.response.data) {
            errorMessage = error.response.data.errorMsg;
        }
        alertify.error(errorMessage)
        return Promise.reject(error.response.data ? error.response.data : error.response);
    }
);